package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.ProjectClass;
import com.xjgzinfo.usdp.domain.AppClass;
import com.xjgzinfo.usdp.repository.ProjectClassRepository;
import com.xjgzinfo.usdp.service.ProjectClassService;
import com.xjgzinfo.usdp.service.dto.ProjectClassDTO;
import com.xjgzinfo.usdp.service.mapper.ProjectClassMapper;
import com.xjgzinfo.usdp.service.dto.ProjectClassCriteria;
import com.xjgzinfo.usdp.service.ProjectClassQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link ProjectClassResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class ProjectClassResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_CODE = "AAAAAAAAAA";
    private static final String UPDATED_CODE = "BBBBBBBBBB";

    private static final Long DEFAULT_TENANT_ID = 1L;
    private static final Long UPDATED_TENANT_ID = 2L;
    private static final Long SMALLER_TENANT_ID = 1L - 1L;

    @Autowired
    private ProjectClassRepository projectClassRepository;

    @Autowired
    private ProjectClassMapper projectClassMapper;

    @Autowired
    private ProjectClassService projectClassService;

    @Autowired
    private ProjectClassQueryService projectClassQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restProjectClassMockMvc;

    private ProjectClass projectClass;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static ProjectClass createEntity(EntityManager em) {
        ProjectClass projectClass = new ProjectClass()
            .name(DEFAULT_NAME)
            .code(DEFAULT_CODE)
            .tenantId(DEFAULT_TENANT_ID);
        return projectClass;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static ProjectClass createUpdatedEntity(EntityManager em) {
        ProjectClass projectClass = new ProjectClass()
            .name(UPDATED_NAME)
            .code(UPDATED_CODE)
            .tenantId(UPDATED_TENANT_ID);
        return projectClass;
    }

    @BeforeEach
    public void initTest() {
        projectClass = createEntity(em);
    }

    @Test
    @Transactional
    public void createProjectClass() throws Exception {
        int databaseSizeBeforeCreate = projectClassRepository.findAll().size();
        // Create the ProjectClass
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);
        restProjectClassMockMvc.perform(post("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isCreated());

        // Validate the ProjectClass in the database
        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeCreate + 1);
        ProjectClass testProjectClass = projectClassList.get(projectClassList.size() - 1);
        assertThat(testProjectClass.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testProjectClass.getCode()).isEqualTo(DEFAULT_CODE);
        assertThat(testProjectClass.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
    }

    @Test
    @Transactional
    public void createProjectClassWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = projectClassRepository.findAll().size();

        // Create the ProjectClass with an existing ID
        projectClass.setId(1L);
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);

        // An entity with an existing ID cannot be created, so this API call must fail
        restProjectClassMockMvc.perform(post("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isBadRequest());

        // Validate the ProjectClass in the database
        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = projectClassRepository.findAll().size();
        // set the field null
        projectClass.setName(null);

        // Create the ProjectClass, which fails.
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);


        restProjectClassMockMvc.perform(post("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isBadRequest());

        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkCodeIsRequired() throws Exception {
        int databaseSizeBeforeTest = projectClassRepository.findAll().size();
        // set the field null
        projectClass.setCode(null);

        // Create the ProjectClass, which fails.
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);


        restProjectClassMockMvc.perform(post("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isBadRequest());

        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkTenantIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = projectClassRepository.findAll().size();
        // set the field null
        projectClass.setTenantId(null);

        // Create the ProjectClass, which fails.
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);


        restProjectClassMockMvc.perform(post("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isBadRequest());

        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllProjectClasses() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList
        restProjectClassMockMvc.perform(get("/api/project-classes?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(projectClass.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].tenantId").value(hasItem(DEFAULT_TENANT_ID.intValue())));
    }
    
    @Test
    @Transactional
    public void getProjectClass() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get the projectClass
        restProjectClassMockMvc.perform(get("/api/project-classes/{id}", projectClass.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(projectClass.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.code").value(DEFAULT_CODE))
            .andExpect(jsonPath("$.tenantId").value(DEFAULT_TENANT_ID.intValue()));
    }


    @Test
    @Transactional
    public void getProjectClassesByIdFiltering() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        Long id = projectClass.getId();

        defaultProjectClassShouldBeFound("id.equals=" + id);
        defaultProjectClassShouldNotBeFound("id.notEquals=" + id);

        defaultProjectClassShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultProjectClassShouldNotBeFound("id.greaterThan=" + id);

        defaultProjectClassShouldBeFound("id.lessThanOrEqual=" + id);
        defaultProjectClassShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllProjectClassesByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name equals to DEFAULT_NAME
        defaultProjectClassShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the projectClassList where name equals to UPDATED_NAME
        defaultProjectClassShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name not equals to DEFAULT_NAME
        defaultProjectClassShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the projectClassList where name not equals to UPDATED_NAME
        defaultProjectClassShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByNameIsInShouldWork() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name in DEFAULT_NAME or UPDATED_NAME
        defaultProjectClassShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the projectClassList where name equals to UPDATED_NAME
        defaultProjectClassShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name is not null
        defaultProjectClassShouldBeFound("name.specified=true");

        // Get all the projectClassList where name is null
        defaultProjectClassShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllProjectClassesByNameContainsSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name contains DEFAULT_NAME
        defaultProjectClassShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the projectClassList where name contains UPDATED_NAME
        defaultProjectClassShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByNameNotContainsSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where name does not contain DEFAULT_NAME
        defaultProjectClassShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the projectClassList where name does not contain UPDATED_NAME
        defaultProjectClassShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllProjectClassesByCodeIsEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code equals to DEFAULT_CODE
        defaultProjectClassShouldBeFound("code.equals=" + DEFAULT_CODE);

        // Get all the projectClassList where code equals to UPDATED_CODE
        defaultProjectClassShouldNotBeFound("code.equals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByCodeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code not equals to DEFAULT_CODE
        defaultProjectClassShouldNotBeFound("code.notEquals=" + DEFAULT_CODE);

        // Get all the projectClassList where code not equals to UPDATED_CODE
        defaultProjectClassShouldBeFound("code.notEquals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByCodeIsInShouldWork() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code in DEFAULT_CODE or UPDATED_CODE
        defaultProjectClassShouldBeFound("code.in=" + DEFAULT_CODE + "," + UPDATED_CODE);

        // Get all the projectClassList where code equals to UPDATED_CODE
        defaultProjectClassShouldNotBeFound("code.in=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByCodeIsNullOrNotNull() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code is not null
        defaultProjectClassShouldBeFound("code.specified=true");

        // Get all the projectClassList where code is null
        defaultProjectClassShouldNotBeFound("code.specified=false");
    }
                @Test
    @Transactional
    public void getAllProjectClassesByCodeContainsSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code contains DEFAULT_CODE
        defaultProjectClassShouldBeFound("code.contains=" + DEFAULT_CODE);

        // Get all the projectClassList where code contains UPDATED_CODE
        defaultProjectClassShouldNotBeFound("code.contains=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByCodeNotContainsSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where code does not contain DEFAULT_CODE
        defaultProjectClassShouldNotBeFound("code.doesNotContain=" + DEFAULT_CODE);

        // Get all the projectClassList where code does not contain UPDATED_CODE
        defaultProjectClassShouldBeFound("code.doesNotContain=" + UPDATED_CODE);
    }


    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId equals to DEFAULT_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.equals=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId equals to UPDATED_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.equals=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId not equals to DEFAULT_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.notEquals=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId not equals to UPDATED_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.notEquals=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsInShouldWork() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId in DEFAULT_TENANT_ID or UPDATED_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.in=" + DEFAULT_TENANT_ID + "," + UPDATED_TENANT_ID);

        // Get all the projectClassList where tenantId equals to UPDATED_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.in=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId is not null
        defaultProjectClassShouldBeFound("tenantId.specified=true");

        // Get all the projectClassList where tenantId is null
        defaultProjectClassShouldNotBeFound("tenantId.specified=false");
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId is greater than or equal to DEFAULT_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.greaterThanOrEqual=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId is greater than or equal to UPDATED_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.greaterThanOrEqual=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId is less than or equal to DEFAULT_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.lessThanOrEqual=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId is less than or equal to SMALLER_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.lessThanOrEqual=" + SMALLER_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsLessThanSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId is less than DEFAULT_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.lessThan=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId is less than UPDATED_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.lessThan=" + UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void getAllProjectClassesByTenantIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        // Get all the projectClassList where tenantId is greater than DEFAULT_TENANT_ID
        defaultProjectClassShouldNotBeFound("tenantId.greaterThan=" + DEFAULT_TENANT_ID);

        // Get all the projectClassList where tenantId is greater than SMALLER_TENANT_ID
        defaultProjectClassShouldBeFound("tenantId.greaterThan=" + SMALLER_TENANT_ID);
    }


    @Test
    @Transactional
    public void getAllProjectClassesByAppClassIsEqualToSomething() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);
        AppClass appClass = AppClassResourceIT.createEntity(em);
        em.persist(appClass);
        em.flush();
        projectClass.addAppClass(appClass);
        projectClassRepository.saveAndFlush(projectClass);
        Long appClassId = appClass.getId();

        // Get all the projectClassList where appClass equals to appClassId
        defaultProjectClassShouldBeFound("appClassId.equals=" + appClassId);

        // Get all the projectClassList where appClass equals to appClassId + 1
        defaultProjectClassShouldNotBeFound("appClassId.equals=" + (appClassId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultProjectClassShouldBeFound(String filter) throws Exception {
        restProjectClassMockMvc.perform(get("/api/project-classes?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(projectClass.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].tenantId").value(hasItem(DEFAULT_TENANT_ID.intValue())));

        // Check, that the count call also returns 1
        restProjectClassMockMvc.perform(get("/api/project-classes/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultProjectClassShouldNotBeFound(String filter) throws Exception {
        restProjectClassMockMvc.perform(get("/api/project-classes?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restProjectClassMockMvc.perform(get("/api/project-classes/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingProjectClass() throws Exception {
        // Get the projectClass
        restProjectClassMockMvc.perform(get("/api/project-classes/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateProjectClass() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        int databaseSizeBeforeUpdate = projectClassRepository.findAll().size();

        // Update the projectClass
        ProjectClass updatedProjectClass = projectClassRepository.findById(projectClass.getId()).get();
        // Disconnect from session so that the updates on updatedProjectClass are not directly saved in db
        em.detach(updatedProjectClass);
        updatedProjectClass
            .name(UPDATED_NAME)
            .code(UPDATED_CODE)
            .tenantId(UPDATED_TENANT_ID);
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(updatedProjectClass);

        restProjectClassMockMvc.perform(put("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isOk());

        // Validate the ProjectClass in the database
        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeUpdate);
        ProjectClass testProjectClass = projectClassList.get(projectClassList.size() - 1);
        assertThat(testProjectClass.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testProjectClass.getCode()).isEqualTo(UPDATED_CODE);
        assertThat(testProjectClass.getTenantId()).isEqualTo(UPDATED_TENANT_ID);
    }

    @Test
    @Transactional
    public void updateNonExistingProjectClass() throws Exception {
        int databaseSizeBeforeUpdate = projectClassRepository.findAll().size();

        // Create the ProjectClass
        ProjectClassDTO projectClassDTO = projectClassMapper.toDto(projectClass);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restProjectClassMockMvc.perform(put("/api/project-classes").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(projectClassDTO)))
            .andExpect(status().isBadRequest());

        // Validate the ProjectClass in the database
        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteProjectClass() throws Exception {
        // Initialize the database
        projectClassRepository.saveAndFlush(projectClass);

        int databaseSizeBeforeDelete = projectClassRepository.findAll().size();

        // Delete the projectClass
        restProjectClassMockMvc.perform(delete("/api/project-classes/{id}", projectClass.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<ProjectClass> projectClassList = projectClassRepository.findAll();
        assertThat(projectClassList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
